<?php
namespace app\admin2\controller;

use think\Session;
use app\common\controller\AdminBaseo;
use app\api\controller\Label as LabelController;

class Label extends AdminBaseo
{
    protected $labelObj;
    protected $config;

    protected function _initialize(){
        $this->labelObj = new LabelController;
        $this->config = session::get('wechat_info');
    }

    /**
     * 查看全部分组
     */
    public function classList(){
        $result_list = $this->labelObj->getLabel($this->config['id']);
        return $result_list;
    }

    /**
     * 获取所有子级标签
     */
    public function sonClassList(){
        $result_list = $this->labelObj->getSonLabelInfo($this->config['id']);
        return $result_list;
    }

    /**
     * 创建父级标签分组
     * @param type name 标签名称
     */
    public function setParentLabel(){
        if($this->request->isPost()){
            $data = $this->request->post();
            $data['auid'] = $this->config['id'];
            $return = $this->labelObj->saveLabel($data);
            if($return) return json(['status'=>1,'msg'=>'ok']);
            return json(['status'=>-1,'msg'=>'save error']);
        }else{
            return json(['status'=>-1,'msg'=>'You bad bad!!You are a SB!!']);
        }
    }

    /**
     * 创建子级标签分组
     * @param type pid 父级id
     * @param type name 标签名称
     */
    public function setSonLabel(){
        if($this->request->isPost()){
            $data = $this->request->post();
            $return = $this->labelObj->saveSonLabel($this->config['id'],$data);
            return $return;
        }else{
            return false;
        }
    }

    /**
     * 编辑标签
     * @param type group_id 组id
     * @param type id 标签id
     * @param type name 标签名称
     * @param type pid 父级id
     */
    public function updateLabel(){
        if($this->request->isPost()){
            $data = $this->request->post();
            $result = $this->labelObj->updateWechatLabel($this->config['id'] , $data);
            return $result;
        }else{
            return json(['status' => -1,'msg' => '错误']);
        }
    }

    /**
     * 删除标签
     * @param type group_id 组id
     * @param type id 标签id
     * @param type pid 父级标签
     */
    public function deleteLabel(){
        if($this->request->isPost()){
            $data = $this->request->post();
            $result = $this->labelObj->delLabel($this->config['id'] , $data);
            return $result;
        }else{
            return json(['status' => -1,'msg' => '错误']);
        }
    }
}